package log

import (
	"io"
	"os"
	"strconv"
	"time"
)

func NewFile(logType string) io.Writer {
	month := int(time.Now().Month())
	day := time.Now().Day()
	path := "storage/logs/" + strconv.Itoa(month)
	// 创建多级目录
	err := os.MkdirAll(path, 0755)
	if err != nil {
		panic("日志目录创建错误:" + err.Error())
	}

	fileName := path + "/" + strconv.Itoa(day) + "_" + logType + ".log"

	file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		panic("日志文件错误:" + err.Error())
	}

	//defer file.Close()

	return file
}
